/**
 * 
 */
package com.jie.eclipse.pan.gef.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.jie.eclipse.pan.bind.BaseDataBind;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.form.item.Date;
import com.jie.eclipse.pan.form.support.FormItem;
import com.jie.eclipse.pan.listener.PJumpCaptionModifyListener;
import com.jie.eclipse.pan.listener.PModifyListener;
import com.jie.eclipse.pan.utils.StringBuilderEx;

/**
 * @author yanjie
 *
 */
public class DateDialog extends BaseDialog{

	/**
	 * @param parentShell
	 * @param data
	 * @param action
	 */
	public DateDialog(Shell parentShell, BaseDataEntity data, String action) {
		super(parentShell, data, action);
	}
	
	@Override
	protected Control createDialogArea(Composite paramComposite) {
		Color bgcolor = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
		Composite composite = new Composite(paramComposite, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		composite.setBackground(bgcolor);
		Label lb = null;
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("名稱:");
		lb.setBackground(bgcolor);
		Text name = new Text(composite, SWT.BORDER);
		name.setLayoutData(new GridData(200, 15));
		this.getDataBind().bind("name", name);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("标题:");
		lb.setBackground(bgcolor);
		Text caption = new Text(composite, SWT.BORDER);
		caption.setLayoutData(new GridData(200, 15));
		this.getDataBind().bind("caption", caption);
		
		name.addModifyListener(new PModifyListener("commonChange",null));
		name.addFocusListener(new PJumpCaptionModifyListener(caption));
		
		lb=  new Label(composite,SWT.RIGHT);
//		lb.setLayoutData(fh);
		lb.setText("列数:");
		lb.setBackground(bgcolor);
		Text colspan = new Text(composite, SWT.BORDER);
		colspan.setLayoutData(new GridData(200, 15));
		this.getDataBind().bind("colspan", colspan);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("為空:");
		lb.setBackground(bgcolor);
		Combo required = new Combo(composite, SWT.READ_ONLY);
		required.setItems(new String[]{"Y","N"});
		required.select(0);
		required.setLayoutData(new GridData(100, 24));
		required.setData("0","false");
		required.setData("1","true");
		this.getDataBind().bind("required", required);
		
		lb=  new Label(composite,SWT.RIGHT);
		lb.setText("配置:");
		lb.setBackground(bgcolor);
		Text calConfig = new Text(composite, SWT.BORDER);
		calConfig.setLayoutData(new GridData(200, 15));
		this.getDataBind().bind("calConfig", calConfig);
		
		this.reloadRecord();
		return paramComposite;
	}
	
	@Override
	public void initRootItem(BaseDataEntity data,BaseDataBind bind,StringBuilderEx code) {
		if(bind == null)return ;
		BaseDataEntity record = bind.getRecord();
		FormItem date = getNewFormItem();
		date.configItem(record,"default");
		this.setRoot(date);
	}
	
	@Override
	public void fillConfig(BaseDataEntity config, BaseDataBind dataBind) {
		super.fillConfig(config, dataBind);
	}
	
	@Override
	public String getTitle() {
		return "日期框設置";
	}
}
